import asyncio
import os

from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.functions import KernelArguments


async def run_function(*args):
   return await kernel.invoke(*args)

if __name__ == "__main__":
    os.environ["OPENAI_API_KEY"] = os.environ["OPENAI_API_KEY_ZHIHU"]
    os.environ["OPENAI_BASE_URL"] = os.environ["OPENAI_API_BASE_ZHIHU"]

    kernel = Kernel()

    service_id = "default"
    service = OpenAIChatCompletion(
        api_key=os.environ["OPENAI_API_KEY_ZHIHU"],
        service_id=service_id,
        ai_model_id="gpt-4o")

    kernel.add_service(service)
    # 加载 semantic function。注意目录结构
    my_plugins = kernel.add_plugin(parent_directory="./", plugin_name="SKPlugin")

    result = asyncio.run(run_function(my_plugins["SQLFunction"],KernelArguments(input="2024年4月有哪些课")))
    print(result)